package com.cyan.app.workflow.fragment;


import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.cyan.app.barcode.CaptureActivity;
import com.cyan.app.workflow.R;
import com.cyan.app.workflow.base.fragment.BaseFragment;

/**
 * A simple {@link Fragment} subclass.
 */
public class SaomaFragment extends BaseFragment {
    public static final String TAG = "SaomaFragment";
    private TextView mTextView;
    private TextView top_bar_middle;
    private Intent mIntent = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mTextView = new TextView(getActivity());
    }

    @Override
    public void onPause() {
        super.onPause();
        if(mIntent!=null) mIntent = null;
    }

    @Override
    public void onResume() {
        super.onResume();
        if(TextUtils.isEmpty(mTextView.getText())) {
            mIntent= new Intent(getActivity(), CaptureActivity.class);
            //startActivityForResult(mIntent, 0x0002);
            //startActivityForResult(new Intent(getActivity(), CaptureActivity.class), 0x0002);
        }
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        _RootView = inflater.inflate(R.layout.layout_report, null);
        return _RootView;
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == 0x0002 && resultCode == -1) {
            String result = "";
            if (data != null) {
                result = data.getStringExtra("result");
            }
            mTextView.setText(result);
            Toast toast = Toast.makeText(getActivity(),result,Toast.LENGTH_LONG);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }
    }

    private void initView(){
        top_bar_middle = (TextView) _RootView.findViewById(R.id.top_bar_middle);
        top_bar_middle.setText(R.string.icon_saoma);
    }
}
